package service.impl;

import dao.UserInfoDao;
import dataBean.UserInfoDo;
import service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

/**
 * Created by lxl on 2015/10/30.
 */
public class AuthorityServiceImpl implements AuthorityService {

    @Autowired
    private UserInfoDao userInfoDao ;

    private HashMap<String,Integer> authorMap = new HashMap<String, Integer>() ;

    @Override
    public int getAuthority(String username) {

        if( authorMap.get(username) != null ){

            return authorMap.get(username) ;

        }

        UserInfoDo userInfoDo = userInfoDao.selectUserInfoByName(username) ;

        if( userInfoDo != null ){

            authorMap.put(userInfoDo.getName(),userInfoDo.getLevel()) ;

            return userInfoDo.getLevel() ;

        }

        return -1;

    }
}
